package com.study.springjson.controller;

import com.study.springjson.dao.mapper.StudentMapper;
import com.study.springjson.model.Student;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.ResponseBody;
import org.springframework.web.servlet.ModelAndView;

import java.util.List;

@Controller
public class StudentController {

    @Autowired
    private StudentMapper studentMapper;

    @RequestMapping("/index")
    public ModelAndView index(ModelAndView modelAndView) {
        List<Student> studentList = studentMapper.findAll();
        modelAndView.addObject("result", studentList);
        modelAndView.setViewName("json");
        return modelAndView;
    }

    @RequestMapping("/list")
    @ResponseBody
    public List<Student> list() {
        return studentMapper.findAll();
    }
}
